package com.jjw.springbootcvs.handler;



import com.jjw.springbootcvs.utils.Result;
import lombok.extern.slf4j.Slf4j;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author jjw
 * @Date 2024-10-25
 * @Description
 */
@RestController
@ControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    /**
     * 捕获业务异常
     * @param ex
     * @return
     */
    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public Result exceptionHandler(RuntimeException ex) {
            log.error("异常信息"+ex.getMessage());
        return Result.error(ex.getMessage());
    }
}